/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package flight.client;

import flight.model.Flight;
import flight.model.FlightList;
import flight.service.FlightService;
import middleware.Callback;
import middleware.Naming;

/**
 *
 * @author VU MINH TAM
 * Flight Service Proxy - implements remote object of FlightService on client's slide
 */
public class FlightServiceProxy implements FlightService{
    Naming connector;
    String myIp;
    public FlightServiceProxy(String ip, Naming naming){
        myIp = ip;
        connector = naming;
    }
    public FlightList getIdsBySourceAndDest(String s, String d) {
        System.out.println("CLIENT: get Ids from " + s + " to " + d);
        Object[] objs = new Object[2];
        objs[0] = s;
        objs[1] = d;
        Object res = connector.send(myIp, "getIdsBySourceAndDest", objs);
        
        return (FlightList)res;
    }

    public Flight getFlightById(int id) {
        Object[] param = new Object[1];
        param[0] = id;
        Object res = connector.send(myIp, "getFlightById", param);
        return (Flight)res;
    }

    public String reserveSeats(int id, int noOfSeats) {
        Object[] param = new Object[2];
        param[0] = id;
        param[1] = noOfSeats;
        return (String)connector.send(myIp, "reserveSeats", param);
    }

    public Object invoke(String methodName, Object[] parameters) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String registerCallbackFlightClient(int flightId, int interval, Callback obj) {
        Object[] param = new Object[3];
        param[0] = flightId;
        param[1] = interval;
        param[2] = "cbHolder";
        return (String)connector.send(myIp, "registerCallbackFlightClient", param);
    }

    public FlightList getFlightsOnDate(String date) {
        Object[] param = {date};
        return (FlightList)connector.send(myIp, "getFlightsOnDate", param);

    }

    public Flight getCheapest() {
        return (Flight)connector.send(myIp, "getCheapest", new Object[0]);
    }

    public String discountPrice(int id, float percentage) {
        Object[] param = new Object[2];
        param[0] = id;
        param[1] = percentage;
        return (String)connector.send(myIp, "discountPrice", param);
    }

}
